package com.ltxtiyu.video.cacheDaoImpl;

import com.ltxtiyu.video.cacheDao.MomentCacheDao;
import com.ltxtiyu.video.dao.ltx.MomentDao;
import com.ltxtiyu.video.entity.Moment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "ltx:moment")
public class MomentCacheDaoImpl implements MomentCacheDao {
    @Autowired
    MomentDao momentDao;

    @Override
    @CacheEvict(key = "#id")
    public int deleteByPrimaryKey(Integer id) {
        return momentDao.deleteByPrimaryKey(id);
    }

    @Override
    @CachePut( key = "#record.id",unless="#result == null")
    public Moment insertSelective(Moment record) {
        momentDao.insertSelective(record);
        return record;
    }

    @Override
    @Cacheable(key = "#id",unless="#result == null")
    public Moment selectByPrimaryKey(Integer id) {
        return momentDao.selectByPrimaryKey(id);
    }

    @Override
    @CachePut(key = "#record.id",unless="#result == null")
    public Moment updateByPrimaryKeySelective(Moment record) {
        momentDao.updateByPrimaryKeySelective(record);
        return record;
    }
}
